<template>
    <div class="demo3">
        <!-- 头部 -->
        <!-- <div class="header">
            <x-icon type="ios-arrow-left" size="" class="icon-white" @click="$router.go(-1)"></x-icon>选择检查单位
        </div> -->
        <!-- 内容部分 -->
        <div class="demo3_main">
            <!-- <noData v-if="arr1 == 0"></noData> -->
            <div class="searchDiv">
                <input type="text"
                       v-model="parmas.data.name"
                       class="search"
                       placeholder="输入关键字搜索">
            </div>
            <div class="list1Box">
                <group v-if="searchList">
                    <radio :options="arr1"
                           @on-change="change"
                           v-model="radios"></radio>
                </group>
                <group v-if="!searchList">
                    <radio :options="arr1"
                           @on-change="change"
                           v-model="radios"></radio>
                </group>
            </div>
        </div>
        <!-- <myMenu @clickBack="back"></myMenu> -->
    </div>
</template>
<script>
import { Radio, Group } from 'vux'
import myMenu from '@/commonComponents/menu'
function unique (arr) {
    return Array.from(new Set(arr))
}
export default {
    data () {
        return {
            show: false,
            radios: '',
            searchList: true,
            parmas: {
                allowPaging: 'true',
                business: 'getDivderPeopleList',
                data: {
                    departId: '',
                    name: ''
                },
                pageIndex: 0,
                pageSize: 20000,
                tokenId: 'A3944C2D655B11D684296E71CB81C9BD',
                userId: ''
            },
            arr1: [],
            arr2: [],
            arr3: []
        }
    },
    components: {
        Radio,
        Group,
        myMenu
    },
    props: {
        selectedFn: {
            type: Function
        }
    },
    created () {
        var token = JSON.parse(window.localStorage.getItem('userInfo'))
        this.parmas.userId = token.userid
        this.parmas.data.departId = token.deptid
        this.radios = this.$route.query.radios
        this.dataArr()
    },
    methods: {
        change (value, label) {
            let realName, memberId
            for (var k of this.arr2) {
                if (k.realName == value) {
                    window.sessionStorage.setItem('teamLeader', k.realName)
                    window.sessionStorage.setItem('teamLeaderId', k.memberId)
                    realName = k.realName
                    memberId = k.memberId
                }
            }
            if (this.selectedFn) {
                this.selectedFn(realName, memberId)
            } else {
                this.$router.go(-1)
            }
        },
        dataArr () {
            this.$axiosAjax.getConfigJson(this.parmas).then((res) => {
                if (res.status) {
                    var arr = []
                    for (var k of res.data.data) {
                        arr.push(k.realName)
                    }
                    this.arr1 = unique(arr)
                    this.arr2 = res.data.data
                }
            }
            )
        }
    },
    watch: {
        'parmas.data.name' (val) {
            if (val) {
                this.arr1 = []
                this.dataArr()
                this.searchList = false
            } else {
                this.dataArr()
                this.searchList = true
            }
        }
    }
}
function getResult (val) {
    let rs = []
    for (let i = 0; i < 20; i++) {
        rs.push({
            title: `${val} result: ${i + 1} `,
            other: i
        })
    }
    return rs
}
</script>
<style lang="less" scope>
.demo3 {
    width: 100%;
    height: 100%;
    .demo3_main {
        // height: 603px;
        height: 100%;
        width: 100%;
        background-color: #ebeef2;
        .searchDiv {
            background-color: #ebeef2;
            padding: 10px 0;
            .search {
                width: 360px;
                margin: 0 auto;
                height: 40px;
                line-height: 40px;
                padding-left: 10px;
                box-sizing: border-box;
                border-radius: 10px;
                display: block;
                border: 1px solid #999;
            }
        }
        .list1Box {
            width: 100%;
            // height: 603px;
            height: 340px;
            float: left;
            background-color: #fff;
            overflow-x: scroll;
            .weui-search-bar__cancel-btn {
                display: none;
            }
        }
    }
    .weui-cells_radio {
        // margin-top: 40px;
    }
    .vux-search-fixed {
        top: 40px;
    }
    .weui-cells.vux-search_show {
        display: none;
    }
    .vux-search-box {
        position: static !important;
    }
}
</style>
